package com.android.thelastnoet.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBOpenHelper extends SQLiteOpenHelper {

    private static DBOpenHelper dbOpenHelper;

    private static  final String DB_NAME = "note.db";
    private static final int DB_VERSION = 1;

    public static synchronized DBOpenHelper getDbOpenHelper(Context context) {
        if(dbOpenHelper==null){
            dbOpenHelper=new DBOpenHelper(context);
        }
        return dbOpenHelper;
    }

    public DBOpenHelper(@Nullable Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    public interface TABLE {
        public static String NOTE = "note";
        public static String USER = "user";
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_NOTE_TABLE =
                "CREATE TABLE note(id INTEGER PRIMARY KEY AUTOINCREMENT,title VARCHAR(30),subContent VARCHAR(30),content text, groupName VARCHAR(20), createTime VARCHAR(20),userId VARCHAR(10))";
        db.execSQL(CREATE_NOTE_TABLE);
        String CREATE_USER_TABLE =
                "CREATE TABLE user(id INTEGER PRIMARY KEY AUTOINCREMENT,userName VARCHAR(30),password VARCHAR(30),csecretLock VARCHAR(20))";
        db.execSQL(CREATE_USER_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
